package com.kate.mall.order.price.coupon;

import com.kate.mall.order.dto.CouponDTO;
import com.kate.mall.order.dto.OrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @Description: 满减券计算组件
 * @Auther: 新梦想*陈超
 * @Date: 2021/10/30 19:35
 */
@Component
@Slf4j
public class ReachDiscountCouponCalculator implements CouponCalculator {


    @Override
    public BigDecimal calculate(OrderDTO order, CouponDTO coupon) throws Exception {
        BigDecimal payableAmount = order.getOrderPrice();

        BigDecimal thresholdAmount = coupon.getMin();
        BigDecimal reduceAmount = coupon.getDiscount();
        log.info("======满减券计算组件优惠券计算组件.......订单总价：{},门槛：{},劵减价格：{}",payableAmount,thresholdAmount,reduceAmount);
        if (payableAmount.compareTo(thresholdAmount) == 1) {
            return reduceAmount;
        }

        return new BigDecimal(0.0);
    }

}